package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TBlessUser;
import com.ruoyi.marry.service.ITBlessUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 点赞管理Controller
 *
 * @author user_marry
 * @date 2020-11-24
 */
@RestController
@RequestMapping("/marry/blessUser")
public class TBlessUserController extends BaseController {

    @Autowired
    private ITBlessUserService tBlessUserService;

    /**
     * 查询点赞管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBlessUser tBlessUser) {
        startPage();
        List<TBlessUser> list = tBlessUserService.selectTBlessUserList(tBlessUser);
        return getDataTable(list);
    }

    /**
     * 查询每个用户所有点赞管理列表(包括用户详细信息)
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(TBlessUser tBlessUser) {
        startPage();
        List<TBlessUser> list = tBlessUserService.selectTBlessUserListAll(tBlessUser.getLoversId());
        return getDataTable(list);
    }

    /**
     * 导出点赞管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:export')")
    @Log(title = "点赞管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TBlessUser tBlessUser) {
        List<TBlessUser> list = tBlessUserService.selectTBlessUserList(tBlessUser);
        ExcelUtil<TBlessUser> util = new ExcelUtil<TBlessUser>(TBlessUser.class);
        return util.exportExcel(list, "blessUser");
    }

    /**
     * 根据点赞编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tBlessUserService.selectTBlessUserById(id));
    }

    /**
     * 新增保存点赞管理
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:add')")
    @Log(title = "点赞管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TBlessUser tBlessUser) {
        return toAjax(tBlessUserService.insertTBlessUser(tBlessUser));
    }

    /**
     * 修改点赞管理
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:edit')")
    @Log(title = "点赞管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBlessUser tBlessUser) {
        return toAjax(tBlessUserService.updateTBlessUser(tBlessUser));
    }

    /**
     * 删除点赞管理
     */
    @PreAuthorize("@ss.hasPermi('marry:blessUser:remove')")
    @Log(title = "点赞管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tBlessUserService.deleteTBlessUserByIds(ids));
    }
}
